﻿<script type="text/javascript">
    var Materials = new Array();

    function initPickTaskGrid() {

        $('#txtTaskDate').datebox("setValue", $.GetYesterday()); //默认取昨天任务的。
      
       // $('#txtTaskDate').datebox({ editable: false });
        var urlstr1 = '@Url.Content("~/BB/AllDictionary/GetStations")';
        $.EUIcombobox("#txtStation", {
            url: urlstr1,
            valueField: 'ID',
            textField: 'Name',
            editable: false,
            // multiple:true,
            datainfo: {},
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }],
            onSelect: function (record) {
                PickTaskGrid();
            }

        });

        //当EditRowID 有值时，修改页面进来，txtTaskDate赋值，并只读
        $('#txtTaskDate').datebox('readonly', false);
        if (EditRowID.length > 1) {
            $('#txtTaskDate').datebox('setValue', EditRowDate);
            $('#txtTaskDate').datebox('readonly', true);
        }

        PickTaskGrid();

    }
    function PickTaskGrid() {


        $('#PickTaskList').datagrid({
           // width: 'auto',
           // height: 'auto',
            height: 440,
            fitColumns: false,
            collapsible: true,
            singleSelect: false,
            selectOnCheck: true, //如果为true，单击复选框将永远选择行。
            checkOnSelect: true,  //如果为true，当用户点击行的时候该复选框就会被选中或取消选中。
            loadMsg: '数据加载中,请稍后……',
            url: '@Url.Content("~/DD/Revisit/GetPickTask")',
           // striped: true,
            // pagination: true,//启用分页，
            rownumbers: true,//显示页码，
            //  pageSize: 15,//设置 页容量5
            //  pageList: [10, 15, 20],//设置 页容量下拉框
            // pagePosition: 'top',
            queryParams: {
                TaskDate: $("#txtTaskDate").datebox('getValue'),
                Station: $("#txtStation").combobox('getValue') ? $("#txtStation").combobox('getValue') : "", //三目运算符
                CallType: $("#CallType").combobox('getValue') ? $("#CallType").combobox('getValue') : 1
            },
            columns: [[
            { field: "ck", checkbox: true },
            { field: "TaskCode", hidden: true },
            { field: "StationName", title: "分站", width: '5%', align: "center", sortable: false, resizable: false },
            { field: "RealAmbulanceSign", title: "车辆", width: '6%', align: "center", sortable: false, resizable: false },
            { field: "AlarmTel", title: "呼救电话", width: '8%', align: "center", sortable: false, resizable: true },
            { field: "LinkCall", title: "联系电话", width: '8%', align: "center", sortable: false, resizable: true },
            { field: "LinkMan", title: "联系人", width: '5%', align: "center", sortable: false, resizable: true },
            { field: "LocalAddr", title: "现场地址", width: '16%', align: "center", sortable: false, resizable: true },
            { field: "PatientName", title: "患者姓名", width: '6%', align: "center", sortable: false, resizable: false },
            { field: "Sex", title: "性别", width: '3%', align: "center", sortable: false, resizable: false },
            { field: "Age", title: "年龄", width: '3%', align: "center", sortable: false, resizable: false },
            { field: "AlarmReason", title: "主诉", width: '8%', align: "center", sortable: false, resizable: true },
            { field: "SendAddr", title: "送往地址", width: '10%', align: "center", sortable: false, resizable: true },
            { field: "StartTaskTime", title: "生成任务时刻", width: '12%', align: "center", formatter: $.formatTime, sortable: false, resizable: true },
            { field: "DispatcherName", title: "责任调度员", width: '5%', align: "center", sortable: false, resizable: true },
            { field: "Driver", title: "司机", width: '5%', align: "center", sortable: false, resizable: true },
            { field: "Doctor", title: "医生", width: '5%', align: "center", sortable: false, resizable: true },
            { field: "Stretcher", title: "担架员", width: '5%', align: "center", sortable: false, resizable: true }
            ]],
            toolbar: [
                 {
                     id: 'btnRevisitView',
                     text: '已勾选回访[0]个',
                     iconCls: 'icon-custom-cGoods',
                     iconWidth: 22,
                     handler: function () {
                         if (Materials.length > 0) {
                             $('#RevisitAddMain').dialog('open');
                             RevistAddMainGrid();
                         } else {
                             $.messager.alert('提示', '请选择回访任务', 'info', function () {
                             });
                         }
                     }
                 }
            ],
            onCheck: function (index, row) {
                if (Materials.length == 0) {
                    Materials.push(row);
                    changeRevisitViewNum();
                    return;
                }
                var boolContain = false;
                $.each(Materials, function (i, info) {
                    if (info.TaskCode == row.TaskCode) {
                        boolContain = true;
                    }
                });
                if (!boolContain) {
                    Materials.push(row);
                }
                changeRevisitViewNum();

            },
            onUncheck: function (index, row) {
                var obj;
                $.each(Materials, function (i, info) {
                    if (info.TaskCode == row.TaskCode) {
                        obj = info;
                    }
                });
                Materials.remove(obj);
                changeRevisitViewNum();
            },

            onCheckAll: function (rows) {


                $.each(rows, function (i, infos) {
                    // var arr = ["xml", "html", "css", "js"];
                    //   $.inArray("js", arr);  //返回 3,
                    //  如果不包含在数组中, 则返回 - 1;

                    var hasmates = false;
                    $.each(Materials, function (index, mates) {
                        if (infos.TaskCode == mates.TaskCode) {
                            hasmates = true;
                        }
                    });
                    // if (Materials.indexOf(rows[ii]) < 0) {  //index用法只能用于string之间，不可以用于数组。
                    if (!hasmates)
                    { Materials.push(infos); }
                }
                );
                changeRevisitViewNum();
            },
            onUncheckAll: function (rows) {
                var obj;
                $.each(rows, function (i, infos) {
                    $.each(Materials, function (index, mates) {
                        if (infos.TaskCode == mates.TaskCode) {
                            //if ($.inArray(rows[i], Materials)>=0){
                            obj = infos;
                           
                        }
                    });
                    Materials.remove(obj);

                    changeRevisitViewNum();
                });
            },


            onLoadSuccess: function (data) {

                var rows = $('#PickTaskList').datagrid('getRows');
                if (rows.length == 0) {
                    $.messager.alert('系统提示', '当前日期无回访任务，或已被全部勾选！', 'info', function () {
                    });


                }
                else {
                    $.messager.show({
                        title: '系统提示',
                        msg: '   成功加载出 ' + data.total + ' 条任务信息！'
                    });
                }
                setViewNumCheck();
                // changeDeliveryViewNum();
            }

        });
    }

    function setViewNumCheck() { //自动勾选已经存在的内容
        var rows = $('#PickTaskList').datagrid('getRows');
        $.each(rows, function (index, item) {
            $.each(Materials, function (i, info) {
                if (item.TaskCode == info.TaskCode) {

                    $('#PickTaskList').datagrid('checkRow', index);
                }
            });
        });
    }


    function changeRevisitViewNum() {
        if (Materials.length == 0) {
            $("#btnRevisitView").linkbutton({
                text: "已勾选回访[" + Materials.length + "]个",
                iconCls: "icon-custom-cGoods"
            });
            $('#txtTaskDate').datebox('readonly', false);
        } else if (Materials.length > 0) {
            $("#btnRevisitView").linkbutton({
                text: "已勾选回访[<strong><span style='color:red'>" + Materials.length + "</span></strong>]个",
                iconCls: "icon-custom-cGoodsFull"
            });
            $('#txtTaskDate').datebox('readonly', true);

        }
    }

    function deleteEditRowID() {
        EditRowID = "";
    }

</script>

<div id="RevisitAddTask" class="easyui-dialog" title="请选择回访的任务" data-options="modal:true,
     collapsible:false,
     minimizable:false,
     maximizable:true,
     closed:true,
     resizable:true,
     iconCls:'icon-custom-cDelivery',
     onClose:function(){ deleteEditRowID();}" style="width: 98%; height: 520px; padding: 0px; ">
    @*<div data-options="region:'center',title:'回访',iconCls:'icon-custom-cPrice'">*@
    <div id="tbb" style="padding: 5px; height: auto">
        <table style="width:99%" cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td align="right" valign="middle" width="8%">任务日期：</td>
                <td align="left" valign="middle" width="13%">
                    <input class="easyui-datebox" style="width:110px" id="txtTaskDate" data-options="editable:false">
                </td>
                <td align="right" valign="middle" width="8%">分站：</td>
                <td align="left" valign="middle" width="13%">
                    <input class="easyui-combobox" style="width: 110px" id="txtStation">
                </td>
                <td align="right" valign="middle" width="8%">来电方式：</td>
                <td align="left" valign="middle" width="13%">
                    <select class="easyui-combobox" style="width: 80px" data-options="panelHeight:90" id="CallType">
                        <option value="1">固话</option>
                        <option value="2">手机</option>
                        <option value="-1">全部</option>
                    </select>
                </td>
                <td width="12%">
                    &nbsp;&nbsp;
                    <a href="javascript:void(0)" id="btnsearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="PickTaskGrid()">查询</a>
                </td>
                <td></td>
            </tr>
        </table>

    </div>
    <div data-options="region:'center'" style="background: #fafafa; overflow: hidden">
        <table id="PickTaskList" border="0"></table>
    </div>
    @*</div>*@
</div>
